// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   CRImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.BN;
import com.sunwayhorizo.health.hl7.datatypes.CD;
import com.sunwayhorizo.health.hl7.datatypes.CR;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.CV;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BLImpl, BNImpl, CDImpl, 
//            CSImpl, CVImpl, NullFlavorImpl, TYPEImpl

public class CRImpl extends ANYImpl
    implements CR
{

    public static final String RCS_ID = "$Header: CRImpl.java 115.19 2005/09/16 09:23:41 amchanda noship $";
    private CV mName;
    private CD mValue;
    private BN mInverted;
    private static final CR nullNI = new CRImpl(CSImpl.valueOf("NI"));
    private static final CR nullOTH = new CRImpl(CSImpl.valueOf("OTH"));
    private static final CR nullNINF = new CRImpl(CSImpl.valueOf("NINF"));
    private static final CR nullPINF = new CRImpl(CSImpl.valueOf("PINF"));
    private static final CR nullUNK = new CRImpl(CSImpl.valueOf("UNK"));
    private static final CR nullASKU = new CRImpl(CSImpl.valueOf("ASKU"));
    private static final CR nullNAV = new CRImpl(CSImpl.valueOf("NAV"));
    private static final CR nullMSK = new CRImpl(CSImpl.valueOf("MSK"));
    private static final CR nullNA = new CRImpl(CSImpl.valueOf("NA"));
    private static final CR nullNASK = new CRImpl(CSImpl.valueOf("NASK"));

    protected CRImpl(CV cv, CD cd, BN bn)
    {
        if(cd == null || cd.isNull().isTrue())
        {
            throw ANYImpl.newNullException("CR", "constructor", "value");
        } else
        {
            mName = cv;
            mValue = cd;
            mInverted = bn;
            return;
        }
    }

    protected CRImpl(CS cs)
    {
        super(true, cs);
    }

    public CV name()
    {
        if(isNull().isTrue())
            return CVImpl.nullCV(NullFlavorImpl.NI);
        else
            return mName;
    }

    public CD value()
    {
        if(isNull().isTrue())
            return CDImpl.nullCD(NullFlavorImpl.NI);
        else
            return mValue;
    }

    public BN inverted()
    {
        if(isNull().isTrue())
            return BNImpl.FALSE;
        else
            return mInverted;
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.CR;
    }

    public int hashCode()
    {
        int i = 17;
        if(isNull().isFalse())
        {
            i = 37 * i + value().hashCode();
            i = 37 * i + (name() != null ? name().hashCode() : 0);
            i = 37 * i + (inverted() != null ? inverted().hashCode() : 0);
        }
        return i;
    }

    public BL equal(ANY any)
    {
        if(any instanceof CR)
        {
            if(any.isNull().booleanValue())
            {
                return BLImpl.FALSE;
            } else
            {
                CR cr = (CR)any;
                return name().equal(cr.name()).and(value().equal(cr.value())).and(inverted().equal(cr.inverted()));
            }
        } else
        {
            return BLImpl.FALSE;
        }
    }

    public static CR valueOf(CV cv, CD cd, BN bn)
    {
        return new CRImpl(cv, cd, bn);
    }

    public static CR valueOf(CV cv, CD cd, boolean flag)
    {
        BN bn = BNImpl.valueOf(flag);
        return valueOf(cv, cd, bn);
    }

    public static CR valueOf(CV cv, CD cd)
    {
        return valueOf(cv, cd, false);
    }

    public static CR valueOf(CD cd)
    {
        CV cv = CVImpl.nullCV(NullFlavorImpl.NI);
        return valueOf(cv, cd, false);
    }

    public static CR nullCR()
    {
        return new CRImpl(null);
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        try
//        {
//            XMLElement xmlelement = (XMLElement)xmldocument.createElement(s);
//            if(inverted() != null)
//                xmlelement.setAttribute("inverted", inverted().isTrue() ? "true" : "false");
//            if(name() != null && name().isNull().isFalse())
//            {
//                XMLNode axmlnode[] = ((CDImpl)name()).writeXML(xmldocument, "name");
//                xmlelement.appendChild(axmlnode[0]);
//            }
//            if(value() != null && value().isNull().isFalse())
//            {
//                XMLNode axmlnode1[] = ((CVImpl)value()).writeXML(xmldocument, "value");
//                xmlelement.appendChild(axmlnode1[0]);
//            }
//            return (new XMLNode[] {
//                xmlelement
//            });
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }

    public static CR nullCR(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
